---
output: 
    pdf_document:
        keep_tex: yes
title: "visits"
geometry: margin=1in
mainfont: cochineal
fontsize: 11pt
linestretch: 1.15
endnote: no
sansitup: no
graphics: yes
toc: yes

header-includes:
- \usepackage{float} 
- \floatplacement{figure}{H} #make every figure with caption = h
- \usepackage{graphicx}
- \usepackage{longtable}
- \LTcapwidth=.95\textwidth
- \linespread{1.05}
- \usepackage{hyperref}
- \usepackage{booktabs}
- \usepackage{subfig}
- \renewcommand{\figurename}{Figure B.}
- \makeatletter
- \def\fnum@figure{\figurename\thefigure}
- \makeatother

---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = F, warning = FALSE, message = F, comment = F)

rm(list=ls())
library(readxl)
library(tidyverse)
library(broom)
library(zoo)
library(lubridate)
library(stargazer)
library(lmtest)
library(sandwich)
library(car)
library(texreg)

# Load data
visits <- read_excel("C:/Users/CSteinert/OneDrive - Universität St.Gallen/Dokumente/unga_bri_project/replication_files/data/data/final_data/visits.xlsx")

# Create country and year variables
visits$country_year <- visits$Country_Year
visits <- separate(visits, col = Country_Year, into = c("country","year"), sep = "_")
visits$year <- as.numeric(visits$year)

# Show only countries treated before 2019
visits_small <- visits %>% filter(country != "Italy") %>% filter(country != "Switzerland")

# Filter to comparable pre and post-treatment periods
visits_small <- visits_small %>% filter(time_to_treat > -6) %>% filter(time_to_treat < 3)

#### Reproduces Figure A.17 ####
#pdf(file = "presidential_visits.pdf", width= 10, height = 8)
ggplot(aes(x = time_to_treat, y = visits_withoutnato), data = visits_small) + geom_col(width = 0.8) +
  theme_bw() + xlab("Time to BRI membership (in years)") +
  ylab("# of presidential visits in the US") + scale_x_continuous(breaks = c(-5, -4, -3, -2, -1, 0, 1, 2)) +
  scale_y_continuous(breaks = c(0, 1, 2, 3, 4, 5, 6)) + geom_vline(xintercept = 0,
               colour = "grey60",
               linetype = 2) + 
  annotate("text", x = 0, y=1.2, label = "BRI joined", size = 5) +theme(axis.text=element_text(size=14),
        axis.title=element_text(size=14))
#dev.off()

# Model-based
m1 <- lm(visits_withoutnato ~ lag(BRI_status) + factor(country), data = visits)
summary(m1)
screenreg(m1)
m2 <- lm(visits_withoutnato ~ BRI_signed + factor(country), data = visits)
summary(m2)

```

